package com.cls.mc_demo.config;

import com.cls.mc_demo.common.CustomCommonAioHandler;
import com.cls.mc_demo.common.HexStringUtil;
import com.cls.mc_demo.common.SPPacket;
import lombok.extern.slf4j.Slf4j;
import org.tio.core.ChannelContext;
import org.tio.core.intf.Packet;

/**
 * 解码器吧
 *
 * @author CLS
 * @since 2023/08/04
 */
@Slf4j
public class CustomClientAioHandler extends CustomCommonAioHandler {

    /**
     * 处理消息
     */
    @Override
    public void handler(Packet packet, ChannelContext channelContext) throws Exception {
        byte[] data = ((SPPacket) packet).getBody();
        log.info("接收的数据为：{}", HexStringUtil.bytesToHexString(data));
    }

    /**
     * 心跳
     */
    @Override
    public SPPacket heartbeatPacket(ChannelContext channelContext) {
//        byte[] s = HexStringUtil.hexToByteArray(Const.HEARTBEAT_SEND_CONTENT);
//        heartbeatPacket.setBody(s);
        return null;
    }
}
